package com.oig.sys.query.support;

import com.oig.common.util.JsonUtil;
import com.oig.sys.query.support.module.QueryExpression;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 *  json格式转成查询语句：
 *
 *  {
 *     "fields": [
 *          {"field": "t1.id", "rename": "id", "cnname": "库存id", "options": {"dataType": "int"}}
 *
 *     ],
 *     "tables": [
 *          {"field": "stock", "rename": "t1", "join": "master", "on": ""}
 *     ],
 *     "group_by": [
 *         //"t1.id"
 *     ],
 *     "order_by":[
 *          {"field":"t1.id","sort":"desc","value":["1","2"]}
 *     ]
 * }
 */
@Slf4j
@Component
public class JsonExpQueryParser implements QueryExpParser {

    /**
     * json字符串转成 object
     * @param expressionStr 表达式字符串
     */
    @Override
    public QueryExpression expressParser(String expressionStr) {
        log.debug("query json : {}", expressionStr);
        return JsonUtil.toObject(expressionStr, QueryExpression.class);
    }


}
